//
//  WHWproxyKitUtility.m
//  WHPersonalData
//
//  Created by jwc on 2021/8/23.
//  Copyright © 2021 mac. All rights reserved.
//


#import "WHWproxyKitUtility.h"
#import "CommonTools.h"
#import "WHWproxyKitModel.h"
#import "NSString+Base64.h"
#import "ParsingXMLUtility.h"
#import "HttpTool.h"
#import "WHFileManager.h"
#import "WHUseCertModel.h"
#import "XMLDictionary.h"
#import "WHRunConfigurationModel.h"
#import "WHWriteLogTool.h"
#import "WHDialog.h"

@interface WHWproxyKitUtility()
//代理服务器地址
@property(nonatomic, strong) NSString *mProxyIP;

//应用ID
@property(nonatomic, strong) NSString *mTargetUri;

//请求代理的参数
@property(nonatomic, strong) NSString *mGetParams;

@property (nonatomic, strong) WHWLProxyTask *task;
@end

@implementation WHWproxyKitUtility

#pragma mark - 单例模式
+ (instancetype)SharedManager:(NSString *)proxyIP targetUri:(NSString *)targetUri getParams:(NSString *)getParams {
      static WHWproxyKitUtility *_instance;
      static dispatch_once_t onceToken;
      dispatch_once(&onceToken, ^{
          _instance = [[WHWproxyKitUtility alloc] init];
          _instance.mProxyIP = proxyIP;
          _instance.mTargetUri = targetUri;
          _instance.mGetParams = getParams;
          [_instance initConfig];
    });

   return _instance;
}

#pragma mark - 初始化代理请求类
- (instancetype)initWithProxyIP:(NSString *)proxyIP targetUri:(NSString *)targetUri getParams:(NSString *)getParams
{
    self = [super init];
    if (self) {
        self.mProxyIP = proxyIP;
        self.mTargetUri = targetUri;
        self.mGetParams = getParams;
        [self initConfig];
    }
    return self;
}

-(void) initConfig{
    self.mHavePrompt = NO;
    self.mHavePromptProgress = NO;
    self.mPromptTxt = @"";
    self.mParamsHaveEncoded = NO;
    self.mUserType = @"1";
    self.mIsDismissPrompt = YES;
    self.mProxyTaskType = WLProxyTaskMethodAsyncGet;
}

#pragma mark 代理初始化参数
- (NSString *)getInvokerIniParam{
    // 公共目录
    NSString *dir = documentsPath;
    // 缓存目录
    NSString *store = documentsPathStore([WHRunConfigurationModel getSystemEnvironment]);
    /**
     <param>
     <uri>终端应用唯一标识</uri>
     <path>/test/path</path>
     <store>接收数据转移目录</store>
     <logv>日志等级(0/1/2/3/4)</logv>
     <challenge>
     <prvkey feed="11">用户私钥BASE64数据</prvkey>
     <mycert feed="11">用户证书BASE64数据</mycert>
     <pscert feed="11">代理证书BASE64数据</pscert>
     <cacert feed="11"> CA 证书BASE64数据</cacert>
     </challenge>
     </param>
     */
    NSString *challenge =@"";
    if ([self.mUserType isEqualToString:@"3"]) {
        //法人
        challenge = [NSString stringWithFormat:@"<challenge><prvkey feed=\"31\">%@</prvkey><mycert feed=\"11\">%@</mycert><pscert feed=\"11\">%@</pscert><cacert feed=\"11\">%@</cacert></challenge>",[WHUseCertModel getWHUseCertModel:WHUseCert_dwpkey dept:self.mLegalId].cert,[WHUseCertModel getWHUseCertModel:WHUseCert_dwcert dept:self.mLegalId].cert,[WHUseCertModel getWHUseCertModel:WHUseCert_ce07].cert,[WHUseCertModel getWHUseCertModel:WHUseCert_cacert].cert];
    }else if([self.mUserType isEqualToString:@"1"])
    {
        //普通用户
        challenge = [NSString stringWithFormat:@"<challenge><mycert feed=\"11\">%@</mycert><pscert feed=\"11\">%@</pscert><cacert feed=\"11\">%@</cacert></challenge>",[WHUseCertModel getWHUseCertModel:WHUseCert_uscert].cert,[WHUseCertModel getWHUseCertModel:WHUseCert_ce07].cert,[WHUseCertModel getWHUseCertModel:WHUseCert_cacert].cert];
    }
    
    // 初始化设置(uri为36位随机数 每次启动，切换运行环境时会变)
    NSString *uri=@"";
    if(challenge.length==0)
    {
        uri =[[NSUUID UUID]UUIDString]; //[CommonTools returnLetterAndNumber:62];
    }else if (kApp.proxyConfgUri.length==0)
    {
        uri =[[NSUUID UUID]UUIDString];
        kApp.proxyConfgUri   = uri;
        kApp.proxyConfgStore = store;
        kApp.proxyConfgChallenge = challenge;
    }else if (![kApp.proxyConfgStore isEqualToString:store]){
        kApp.proxyConfgStore = store;
        uri =[[NSUUID UUID]UUIDString];
        kApp.proxyConfgUri = uri;
    }else if (![kApp.proxyConfgChallenge isEqualToString:challenge]){
        kApp.proxyConfgChallenge = challenge;
        uri =[[NSUUID UUID]UUIDString];
        kApp.proxyConfgUri = uri;
    }else{
        uri = kApp.proxyConfgUri;
    }
    
    NSString *session =session(uri,dir,store,challenge);
    return session;
}

#pragma mark 代理请求
- (void)getSyncActionWithprogress:(void (^)(NSString *result))progress
                          success:(void (^)(NSString *result,NSString *xml,NSString *path))success
                          failure:(void (^)(NSString *result))failure{
    WMZDialog *dialog;
    if (self.mHavePrompt) {
        dialog = [[WHDialog sharedManager] showHudWithText:self.mPromptTxt];
    }
    if (self.mHavePromptProgress) {
        dialog = [[WHDialog sharedManager] showProgressHUDWithText:self.mPromptTxt];
    }
    
    NSString *session = [self getInvokerIniParam];
    NSLog(@"代理--session初始化参数 = %@", session);
    
    /**
     普通用户设为 1
     法人用户设为 3
     没有用户为 0
     <param>
         <proxy challenge="1">10.0.0.100:9000</proxy>
         <target></target>
         <cipher></cipher>
         <timeout></timeout>
     </param>
     */
    NSString *config = config(self.mUserType,self.mProxyIP,self.mTargetUri);//config(self.mIsLegal?@"3":@"1",@"103.39.220.250:9005",@"DI20210513093556100000001");
    NSLog(@"代理--config请求参数 = %@", config);
    NSLog(@"代理--param请求参数 = %@",self.mGetParams);
    if (self.mParamsHaveEncoded) {
        self.mGetParams = [NSString base64withGBKEendedString:self.mGetParams];
    }
    
    //先判断网络，有则执行，没有则不执行
    if (kApp.isHadNetwork) {
        //异步加载
//        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            // 处理耗时操作的代码块...
            [WHDialog sharedManager].mDialog.mWproxyId = [WHWLProxySession requestWithSession:session Method:self.mProxyTaskType config:config params:self.mGetParams custom:nil progress:^(NSString *result) {
                /**
                 <info>
                     <doing_file>当前上传/下载文件名</doing_file>
                     <doing_pos> 当前文件进度(bytes)</doing_pos>
                     <doing_size>当前文件大小(bytes)</doing_size>
                     <total_pos> 所有文件进度(bytes)</total_pos>
                     <total_size>所有文件大小(bytes)</total_size>
                 </info>
                 */
                NSLog(@"代理返回--progress = %@", result);
                NSMutableArray *retlist = [ParsingXMLUtility parsingXML:result NodeString:@"//info" getStringNodes:@[]];
                if(retlist.count>0){
                    if (self.mHavePromptProgress) {
                        NSDictionary *retdic = retlist[0];
                        CGFloat temp  = [retdic[@"total_pos"] floatValue]/[retdic[@"total_size"] floatValue];
                        [[WHDialog sharedManager] updateAlertTypeDownProgress:temp Dialog:dialog];
        //                int valueInt = floor(temp*100);//ceil向上取整 floor 想下
        //                [SVProgressHUD showProgress:temp status:[NSString stringWithFormat:@"%@(%d%@)",self.mPromptTxt,valueInt,@"%"]];
                        if ([retdic[@"total_pos"] isEqualToString:retdic[@"total_size"]] && self.mIsDismissPrompt) {
                            sleep(1);
                            [[WHDialog sharedManager] dismissWithDialog:dialog];
                        }
                    }
                }
                progress(result);
            } success:^(NSString *result) {
                NSLog(@"代理返回--success = %@", result);
                if (self.mProxyTaskType == WLProxyTaskMethodAsyncPut ||self.mProxyTaskType == WLProxyTaskMethodSyncPut) {
                    NSDictionary *dict =[NSDictionary dictionaryWithXMLString:result];
                    NSString * jsonstr = dict[@"jsonstr"];
                    NSString *base64DecodedXml = [jsonstr base64WithGBKDecodedString];
                    NSLog(@"代理返回--success-解码之后的xml = %@", base64DecodedXml);
                    if ((self.mHavePrompt || self.mHavePromptProgress) && self.mIsDismissPrompt) {
                        [[WHDialog sharedManager] closeAllDialogWithDialog:dialog];
                    }
                    success(result,base64DecodedXml,@"");
                }else{
                    NSMutableArray*successModels = [WHWproxyKitModel wHWproxyKitSuccessModelWithResult:result];
                    //获取返回txt文件的路径
                    NSString *path = [WHWproxyKitModel getTxtFilePathWithArray:successModels];
                    NSString *base64Path = [WHFileManager base64EncodedFilePath:path];
                    //获取txt文件的内容
                    NSString *xml = @"";
                    if ([WHFileManager isExistsAtPath:base64Path]) {
                        xml = [WHWproxyKitModel readJsonTxtFileWithPath:base64Path];
                        path = base64Path;
                    }else{
                        xml = [WHWproxyKitModel readJsonTxtFileWithPath:path];
                    }
                    NSLog(@"代理返回--success-txt里面的xml = %@", xml);
                    //获取txt文件的内容解码
                    NSString *base64DecodedXml = [xml base64WithGBKDecodedString];
                    NSLog(@"代理返回--success-解码之后的xml = %@", base64DecodedXml);
                    if ((self.mHavePrompt || self.mHavePromptProgress) && self.mIsDismissPrompt) {
                        [[WHDialog sharedManager] closeAllDialogWithDialog:dialog];
                    }
                    success(result,base64DecodedXml,path);
                }
            } failure:^(NSString *result) {
                NSLog(@"代理返回--failure = %@", result);
                if ((self.mHavePrompt || self.mHavePromptProgress) && self.mIsDismissPrompt) {
                    [[WHDialog sharedManager] closeAllDialogWithDialog:dialog];
                }
                NSMutableArray *re = [ParsingXMLUtility parsingXML:result NodeString:@"//info" getStringNodes:@[]];
                if (self.mHavePrompt || self.mHavePromptProgress) {
                    if(re.count>0){
                        NSString *code = re[0][@"error_code"];
                        NSString *msg  = re[0][@"error_msg"];
                        [[WHDialog sharedManager] showHudErrorWithText:msg];
                        [WHWriteLogTool writeLogInfomation:[NSString stringWithFormat:@"WHWproxyKitUtility---session:%@",session]];
                        [WHWriteLogTool writeLogInfomation:[NSString stringWithFormat:@"WHWproxyKitUtility---config:%@",config]];
                        [WHWriteLogTool writeLogInfomation:[NSString stringWithFormat:@"WHWproxyKitUtility---错误原因:%@",[WHWLProxySession getErrorTitleWithRe:[code intValue]]]];
                    }else{
                        [[WHDialog sharedManager] showHudErrorWithText:@"数据解析错误，请检查"];
                    }
                }else{
                    if(re.count>0){
    //                    NSString *code = re[0][@"error_code"];
                        NSString *msg  = re[0][@"error_msg"];
                        failure(msg);
                    }else{
                        failure(result);
                    }
                }
                
            }];
//        });
    }else{
        [[WHDialog sharedManager] closeAllDialogWithDialog:dialog];
        [[WHDialog sharedManager] showHudErrorWithText:@"没有网络，请检查！"];
        //failure(@"没有网络，请检查！");
    }
}

#pragma mark html代理请求
- (void)getWebSyncWithprogress:(void (^)(NSString *result))progress
                       success:(void (^)(NSString *result,NSString *xml,NSString *path))success
                       failure:(void (^)(NSString *result))failure{
    WMZDialog *dialog;
    if (self.mHavePrompt) {
        dialog = [[WHDialog sharedManager] showHudWithText:self.mPromptTxt];
    }
    if (self.mHavePromptProgress) {
        dialog = [[WHDialog sharedManager] showProgressHUDWithText:self.mPromptTxt];
    }
    
    NSString *session = [self getInvokerIniParam];
    NSLog(@"代理--session初始化参数 = %@", session);
    NSString *config = config(self.mUserType,self.mProxyIP,self.mTargetUri);
    NSLog(@"代理--config请求参数 = %@", config);
    NSLog(@"代理--param请求参数 = %@",self.mGetParams);
    if (self.mParamsHaveEncoded) {
        self.mGetParams = [NSString base64withGBKEendedString:self.mGetParams];
    }
    
    //先判断网络，有则执行，没有则不执行
    if (kApp.isHadNetwork) {
//        [WHWLProxySession configTaskParams:session];
        [WHDialog sharedManager].mDialog.mWproxyId = [WHWLProxySession requestWithSession:session Method:self.mProxyTaskType config:config params:self.mGetParams custom:nil progress:^(NSString *result) {
            /**
             <info>
                 <doing_file>当前上传/下载文件名</doing_file>
                 <doing_pos> 当前文件进度(bytes)</doing_pos>
                 <doing_size>当前文件大小(bytes)</doing_size>
                 <total_pos> 所有文件进度(bytes)</total_pos>
                 <total_size>所有文件大小(bytes)</total_size>
             </info>
             */
            NSLog(@"代理返回--progress = %@", result);
            NSMutableArray *retlist = [ParsingXMLUtility parsingXML:result NodeString:@"//info" getStringNodes:@[]];
            if(retlist.count>0){
                if (self.mHavePromptProgress) {
                    NSDictionary *retdic = retlist[0];
                    CGFloat temp  = [retdic[@"total_pos"] floatValue]/[retdic[@"total_size"] floatValue];
                    [[WHDialog sharedManager] updateAlertTypeDownProgress:temp Dialog:dialog];
                    if ([retdic[@"total_pos"] isEqualToString:retdic[@"total_size"]] && self.mIsDismissPrompt) {
                        sleep(1);
                        [[WHDialog sharedManager] dismissWithDialog:dialog];
                    }
                }
            }
            progress(result);
        } success:^(NSString *result) {
            NSLog(@"代理返回--success = %@", result);
            if (self.mProxyTaskType == WLProxyTaskMethodAsyncPut ||self.mProxyTaskType == WLProxyTaskMethodSyncPut) {
                NSDictionary *dict =[NSDictionary dictionaryWithXMLString:result];
                NSString * jsonstr = dict[@"jsonstr"];
                NSString *base64DecodedXml = [jsonstr base64WithGBKDecodedString];
                NSLog(@"代理返回--success-解码之后的xml = %@", base64DecodedXml);
                if ((self.mHavePrompt || self.mHavePromptProgress) && self.mIsDismissPrompt) {
                    [[WHDialog sharedManager] closeAllDialogWithDialog:dialog];
                }
                success(result,base64DecodedXml,@"");
            }else{
                NSMutableArray*successModels = [WHWproxyKitModel wHWproxyKitSuccessModelWithResult:result];
                //获取返回txt文件的路径
                NSString *path = [WHWproxyKitModel getTxtFilePathWithArray:successModels];
                NSString *base64Path = [WHFileManager base64EncodedFilePath:path];
                //获取txt文件的内容
                NSString *xml = @"";
                if ([WHFileManager isExistsAtPath:base64Path]) {
                    xml = [WHWproxyKitModel readJsonTxtFileWithPath:base64Path];
                    path = base64Path;
                }else{
                    xml = [WHWproxyKitModel readJsonTxtFileWithPath:path];
                }
                NSLog(@"代理返回--success-txt里面的xml = %@", xml);
                //获取txt文件的内容解码
                NSString *base64DecodedXml = [xml base64WithGBKDecodedString];
                NSLog(@"代理返回--success-解码之后的xml = %@", base64DecodedXml);
                if ((self.mHavePrompt || self.mHavePromptProgress) && self.mIsDismissPrompt) {
                    [[WHDialog sharedManager] closeAllDialogWithDialog:dialog];
                }
                success(result,base64DecodedXml,path);
            }
        } failure:^(NSString *result) {
            NSLog(@"代理返回--failure = %@", result);
            if ((self.mHavePrompt || self.mHavePromptProgress) && self.mIsDismissPrompt) {
                [[WHDialog sharedManager] closeAllDialogWithDialog:dialog];
            }
            NSMutableArray *re = [ParsingXMLUtility parsingXML:result NodeString:@"//info" getStringNodes:@[]];
            if (self.mHavePrompt || self.mHavePromptProgress) {
                if(re.count>0){
                    NSString *code = re[0][@"error_code"];
                    NSString *msg  = re[0][@"error_msg"];
                    [[WHDialog sharedManager] showHudErrorWithText:msg];
                    [WHWriteLogTool writeLogInfomation:[NSString stringWithFormat:@"WHWproxyKitUtility---session:%@",session]];
                    [WHWriteLogTool writeLogInfomation:[NSString stringWithFormat:@"WHWproxyKitUtility---config:%@",config]];
                    [WHWriteLogTool writeLogInfomation:[NSString stringWithFormat:@"WHWproxyKitUtility---错误原因:%@",[WHWLProxySession getErrorTitleWithRe:[code intValue]]]];
                }else{
                    [[WHDialog sharedManager] showHudErrorWithText:@"数据解析错误，请检查"];
                }
            }else{
                if(re.count>0){
                    NSString *msg  = re[0][@"error_msg"];
                    failure(msg);
                }else{
                    failure(result);
                }
            }
            
        }];
    }else{
        [[WHDialog sharedManager] closeAllDialogWithDialog:dialog];
        failure(@"没有网络，请检查！");
    }
}

#pragma mark 取消代理请求
+ (void)cancelRequestWithIdentifierWithID:(NSString *)Identifier{
    [WHWLProxySession cancelRequestWithIdentifier:Identifier];
}

#pragma mark 凭证文件请求视频代理初始化参数
+ (NSString *)getVideoInvokerIniParam{
    // 公共目录
    NSString *dir = videoPath;
    // 缓存目录
    NSString *store =@"";//documentsPathStore([WHRunConfigurationModel getSystemEnvironment]);
    /**
     <param>
     <uri>终端应用唯一标识</uri>
     <path>/test/path</path>
     <store>接收数据转移目录</store>
     <logv>日志等级(0/1/2/3/4)</logv>
     <challenge>
     <prvkey feed="11">用户私钥BASE64数据</prvkey>
     <mycert feed="11">用户证书BASE64数据</mycert>
     <pscert feed="11">代理证书BASE64数据</pscert>
     <cacert feed="11"> CA 证书BASE64数据</cacert>
     </challenge>
     </param>
     */
    NSString *challenge =@"";
    
    // 初始化设置(uri为36位随机数 每次启动，切换运行环境时会变)
    NSString *uri = [[NSUUID UUID]UUIDString];
    
    NSString *session =session(uri,dir,store,challenge);
    return session;
}

#pragma mark 老的代理请求单任务单请求模式
//- (void)getMoreSyncActionWithprogress:(void (^)(NSString *result))progress
//                  success:(void (^)(NSString *result,NSString *xml,NSString *path))success
//                  failure:(void (^)(NSString *result))failure{
//    WMZDialog *dialog;
//    if (self.mHavePrompt) {
//        dialog = [[WHDialog sharedManager] showHudWithText:self.mPromptTxt];
//    }
//    if (self.mHavePromptProgress) {
//        dialog = [[WHDialog sharedManager] showProgressHUDWithText:self.mPromptTxt];
//    }
//    // 初始化设置
//    NSString *uri = [CommonTools returnLetterAndNumber:62];
//    // 公共目录
//    NSString *dir = documentsPath;
//    // 缓存目录
//    NSString *store = documentsPathStore([WHRunConfigurationModel getSystemEnvironment]);
//    /**
//     <param>
//         <uri>终端应用唯一标识</uri>
//         <path>/test/path</path>
//         <store>接收数据转移目录</store>
//         <logv>日志等级(0/1/2/3/4)</logv>
//         <challenge>
//             <prvkey feed="11">用户私钥BASE64数据</prvkey>
//             <mycert feed="11">用户证书BASE64数据</mycert>
//             <pscert feed="11">代理证书BASE64数据</pscert>
//             <cacert feed="11"> CA 证书BASE64数据</cacert>
//         </challenge>
//     </param>
//     */
//    NSString *challenge = @"";
//    if ([self.mUserType isEqualToString:@"3"]) {
//        //法人
//        challenge = [NSString stringWithFormat:@"<challenge><prvkey feed=\"31\">%@</prvkey><mycert feed=\"11\">%@</mycert><pscert feed=\"11\">%@</pscert><cacert feed=\"11\">%@</cacert></challenge>",[WHUseCertModel getWHUseCertModel:WHUseCert_dwpkey dept:self.mLegalId].cert,[WHUseCertModel getWHUseCertModel:WHUseCert_dwcert dept:self.mLegalId].cert,[WHUseCertModel getWHUseCertModel:WHUseCert_ce07].cert,[WHUseCertModel getWHUseCertModel:WHUseCert_cacert].cert];
//    }else if([self.mUserType isEqualToString:@"1"])
//    {
//        //普通用户
//        challenge = [NSString stringWithFormat:@"<challenge><mycert feed=\"11\">%@</mycert><pscert feed=\"11\">%@</pscert><cacert feed=\"11\">%@</cacert></challenge>",[WHUseCertModel getWHUseCertModel:WHUseCert_uscert].cert,[WHUseCertModel getWHUseCertModel:WHUseCert_ce07].cert,[WHUseCertModel getWHUseCertModel:WHUseCert_cacert].cert];
//    }
//
//    NSString *session =session(uri,dir,store,challenge);
//    NSLog(@"代理--session初始化参数 = %@", session);
//
//    /**
//     普通用户设为 1
//     法人用户设为 3
//     没有用户为 0
//     <param>
//         <proxy challenge="1">10.0.0.100:9000</proxy>
//         <target></target>
//         <cipher></cipher>
//         <timeout></timeout>
//     </param>
//     */
//    NSString *config = config(self.mUserType,self.mProxyIP,self.mTargetUri);//config(self.mIsLegal?@"3":@"1",@"103.39.220.250:9005",@"DI20210513093556100000001");
//    NSLog(@"代理--config请求参数 = %@", config);
//    NSLog(@"代理--param请求参数 = %@",self.mGetParams);
//    if (self.mParamsHaveEncoded) {
//        self.mGetParams = [NSString base64withGBKEendedString:self.mGetParams];
//    }
//
//    //先判断网络，有则执行，没有则不执行
//    if (kApp.isHadNetwork) {
//        self.task = [WLProxyTask taskWithSession:session config:config params:self.mGetParams custom:nil method:self.mProxyTaskType progress:^(NSString *result) {
//            /**
//             <info>
//                 <doing_file>当前上传/下载文件名</doing_file>
//                 <doing_pos> 当前文件进度(bytes)</doing_pos>
//                 <doing_size>当前文件大小(bytes)</doing_size>
//                 <total_pos> 所有文件进度(bytes)</total_pos>
//                 <total_size>所有文件大小(bytes)</total_size>
//             </info>
//             */
//            NSLog(@"代理返回--progress = %@", result);
//            NSMutableArray *retlist = [ParsingXMLUtility parsingXML:result NodeString:@"//info" getStringNodes:@[]];
//            if(retlist.count>0){
//                if (self.mHavePromptProgress) {
//                    NSDictionary *retdic = retlist[0];
//                    CGFloat temp  = [retdic[@"total_pos"] floatValue]/[retdic[@"total_size"] floatValue];
//                    [[WHDialog sharedManager] updateAlertTypeDownProgress:temp Dialog:dialog];
//    //                int valueInt = floor(temp*100);//ceil向上取整 floor 想下
//    //                [SVProgressHUD showProgress:temp status:[NSString stringWithFormat:@"%@(%d%@)",self.mPromptTxt,valueInt,@"%"]];
//                    if ([retdic[@"total_pos"] isEqualToString:retdic[@"total_size"]] && self.mIsDismissPrompt) {
//                        sleep(1);
//                        [[WHDialog sharedManager] dismissWithDialog:dialog];
//                    }
//                }
//            }
//            progress(result);
//        } success:^(NSString *result) {
//            NSLog(@"代理返回--success = %@", result);
//            if (self.mProxyTaskType == WLProxyTaskMethodAsyncPut ||self.mProxyTaskType == WLProxyTaskMethodSyncPut) {
//                NSDictionary *dict =[NSDictionary dictionaryWithXMLString:result];
//                NSString * jsonstr = dict[@"jsonstr"];
//                NSString *base64DecodedXml = [jsonstr base64WithGBKDecodedString];
//                NSLog(@"代理返回--success-解码之后的xml = %@", base64DecodedXml);
//                if ((self.mHavePrompt || self.mHavePromptProgress) && self.mIsDismissPrompt) {
//                    [[WHDialog sharedManager] closeAllDialogWithDialog:dialog];
//                }
//                success(result,base64DecodedXml,@"");
//            }else{
//                NSMutableArray*successModels = [WHWproxyKitModel wHWproxyKitSuccessModelWithResult:result];
//                //获取返回txt文件的路径
//                NSString *path = [WHWproxyKitModel getTxtFilePathWithArray:successModels];
//                NSString *base64Path = [WHFileManager base64EncodedFilePath:path];
//                //获取txt文件的内容
//                NSString *xml = @"";
//                if ([WHFileManager isExistsAtPath:base64Path]) {
//                    xml = [WHWproxyKitModel readJsonTxtFileWithPath:base64Path];
//                    path = base64Path;
//                }else{
//                    xml = [WHWproxyKitModel readJsonTxtFileWithPath:path];
//                }
//                NSLog(@"代理返回--success-txt里面的xml = %@", xml);
//                //获取txt文件的内容解码
//                NSString *base64DecodedXml = [xml base64WithGBKDecodedString];
//                NSLog(@"getMoreSyncActionWithprogress代理返回--success-解码之后的xml = %@", base64DecodedXml);
//                if ((self.mHavePrompt || self.mHavePromptProgress) && self.mIsDismissPrompt) {
//                    [[WHDialog sharedManager] closeAllDialogWithDialog:dialog];
//                }
//                success(result,base64DecodedXml,path);
//            }
//        } failure:^(NSString *result) {
//            NSLog(@"代理返回--failure = %@", result);
//            if ((self.mHavePrompt || self.mHavePromptProgress) && self.mIsDismissPrompt) {
//                [[WHDialog sharedManager] closeAllDialogWithDialog:dialog];
//            }
//            NSMutableArray *re = [ParsingXMLUtility parsingXML:result NodeString:@"//info" getStringNodes:@[]];
//            if (self.mHavePrompt || self.mHavePromptProgress) {
//                if(re.count>0){
////                    NSString *code = re[0][@"error_code"];
//                    NSString *msg  = re[0][@"error_msg"];
//                    [[WHDialog sharedManager] showHudErrorWithText:msg];
//                }else{
//                    [[WHDialog sharedManager] showHudErrorWithText:@"数据解析错误，请检查"];
//                }
//            }
//
//            failure(result);
//        }];
//
//        //异步加载
////        dispatch_async(dispatch_get_global_queue(0, 0), ^{
////          // 处理耗时操作的代码块...
////          [self.task requestTask];
////        });
//        dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(0.5 * NSEC_PER_SEC)),dispatch_get_main_queue(), ^{
//            [self.task requestTask];
//        });
//
//
////        dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
////                                     (int64_t)(0.2 * NSEC_PER_SEC)),dispatch_get_main_queue(), ^{
////         [self.task requestTask];
////        });
//    }else{
//        [[WHDialog sharedManager] closeAllDialogWithDialog:dialog];
//        failure(@"没有网络，请检查！");
//    }
//}

@end
